#ifndef _dbos_demo_oodb_Table01_h
#define _dbos_demo_oodb_Table01_h

#include <nemesis.dbms.Integer.h>
#include <nemesis.dbms.String.h>

#include <nemesis.dbos.Object.h>
#include <nemesis.dbos.ObjectFacade.h>
#include <nemesis.dbos.Loader.h>

namespace nemesis {
   namespace dbms {
      class Database;
      class Connection;
   }
   namespace dbos {
      class Repository;
   }
}

namespace dbos_demo {

namespace oodb {

class Table02;
class Table03;

using namespace nemesis;

class Table01 : public dbos::Object, public dbos::ObjectFacade <Table01> {
public:
   std::string asString () const throw ();

   static void setup (dbms::Database&, dbos::Repository&) throw (RuntimeException);
   static Table01* instanciate (dbms::Connection&, const int id) throw (RuntimeException);

private:
   class Loader : public dbos::Loader {
   public:
      Loader (dbms::Database& database) :
         dbos::Loader (database),
         a_ref02 (true),
         a_ref03 (true)
      {;}

      Loader& setKey (const int id) throw () { a_id = id; return *this; }

      const dbms::Integer& getId () const throw () { return a_id; }
      const dbms::Integer& getTable02 () const throw () { return a_ref02; }
      const dbms::Integer& getTable03 () const throw () { return a_ref03; }

      dbos::Index getIndex () const throw () { return a_id; }
      std::string asString () const throw ();

   private:
      dbms::Integer a_id;
      dbms::Integer a_ref02;
      dbms::Integer a_ref03;

      dbms::Statement* initialize (dbms::Database&) throw (RuntimeException);
   };

   int a_id;
   Table02* a_table02;
   Table03* a_table03;

   static Loader* st_loader;

   Table01 () : a_table02 (NULL), a_table03 (NULL) { ; }
   Table01 (const Table01&);

   void initialize (dbos::Loader& loader) throw (RuntimeException, dbms::DatabaseException);
   void destroy () throw ();

   static const char* getStorageAreaName () throw () { return "oodb::Table01"; }
   static const dbos::Size getMaxSize () throw () {  return 8; }

   dbos_declare_object (Table01);
};

}
}

#endif
